{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EARLY (FREQUENT) RIDERS ONLY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "23100"
      ],
      "text/latex": [
       "23100"
      ],
      "text/markdown": [
       "23100"
      ],
      "text/plain": [
       "[1] 23100"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE )\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"formula.tools\"))\n",
    "Sys.getpid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "route_field <- sprintf(\"route_%s_10_ride\",1:21)\n",
    "\n",
    "commute_ride_data[,I405HOV:=0 + (date > as.Date(\"2015-09-25\"))]\n",
    "#commute_ride_data[,.N,keyby=.(date,I405HOV)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on EARLY RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Early riders only\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1792156</td><td>640522 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1792156 & 640522 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1792156 | 640522  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1792156 640522"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "cat(\"Full Data\\n\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "commute_ride_data = commute_ride_data[early_riders]\n",
    "\n",
    "cat(\"Early riders only\\n\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "#commute_ride_data[,1,aid][,.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),.N]\n",
    "#commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV),1,aid][,.N]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DONE"
     ]
    }
   ],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=c(\"fDate\",route_field),# up to 231 levels\n",
    "                                        quick=FALSE,\n",
    "                                        boot.reps=1001,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "    .updated = as.character(update(FMLA,~.))\n",
    "    if(length(.updated)>1){\n",
    "        .rhs = .updated[3]\n",
    "    }else{\n",
    "        .rhs = strsplit(as.character(update(FMLA,~.)),\" *~ *\")[[1]][2]\n",
    "    }\n",
    "    .terms = strsplit(.rhs,\" *\\\\+ *\")[[1]]\n",
    "    \n",
    "    \n",
    "    .vars = get.vars(rhs(FMLA))\n",
    "    if(any(! (.vars %in% names(data))))\n",
    "           stop(paste(\"missing variable: \",.vars[! (.vars %in% names(data))],collapse=\"\\\\n\"))\n",
    "           \n",
    "    if(any(!(predictors %in% .terms))){\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        cat(\"terms :\\n\")\n",
    "        cat(paste0(.terms,\"\\n\"))\n",
    "        cat(\"\\npredictors :\\n\")\n",
    "        cat(paste0(predictors[!(predictors %in% .terms)],\"\\n\"))\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        stop(\"Bad Predctors\")\n",
    "        \n",
    "    }    \n",
    "    \n",
    "    quick_N <- 5e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "    \n",
    "\n",
    "    # FIT THE OLS MODELS\n",
    "    if(TRUE){\n",
    "        \n",
    "        (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "        .lm0 <- lm(FMLA, data = data) # Useful for extracting the R-squared value\n",
    "        LM <- glm(FMLA, data = data) # required for the wild bootstrap\n",
    "    }else{\n",
    "        (FMLA_main <- formula(paste(lhs,'~',paste(c(predictors),collapse=' + '))))\n",
    "        (FMLA_fixed <- formula(paste('~',paste(adjust_for,collapse=' + '))))\n",
    "\n",
    "        # doesn't work (LM <- lm_robust(FMLA_main,  data = data, fixed = FMLA_fixed) )\n",
    "        (LM <- do.call(lm_robust,list(FMLA_main, data = data, fixed = FMLA_fixed,se_type=\"classical\") )) # I hate magic\n",
    "    }\n",
    "    \n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "   \n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "    \n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[predictors,])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "        \n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "\n",
    "    # DO THE WILD BOOTSTRAP\n",
    "    # set.seed(10101)\n",
    "    # cl <-cluster.wild.glm(LM, dat = data, cluster = ~ factor(favorite_route), boot.reps = boot.reps, report=FALSE )\n",
    "\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    # without doing the (slow) wild bootstrap\n",
    "    out <- cbind(model=model,\n",
    "                rbind(coef(summary(LM))[predictors,]),\n",
    "                # rbind(cl$ci[predictors,]),\n",
    "                r2= summary(.lm0)$r.squared,\n",
    "                N=data[,.N],\n",
    "                granularity=granularity)\n",
    "\n",
    "    rm(LM); gc() # alas...\n",
    "    # dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} \n",
    "cat(\"DONE\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.367577e-02 1.421739e-03 1.665268e+01 2.944742e-62 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                           </td><td>0.0236757651855375          </td><td>0.00142173916370504         </td><td>16.6526784869867            </td><td>2.94474161476437e-62        </td><td>0.276629897089897           </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                & 0.0236757651855375               & 0.00142173916370504              & 16.6526784869867                 & 2.94474161476437e-62             & 0.276629897089897                & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                            | 0.0236757651855375           | 0.00142173916370504          | 16.6526784869867             | 2.94474161476437e-62         | 0.276629897089897            | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 1     0.0236757651855375 0.00142173916370504 16.6526784869867\n",
       "     Pr(>|t|)             r2                N      \n",
       "[1,] 2.94474161476437e-62 0.276629897089897 1104348\n",
       "     granularity                 \n",
       "[1,] rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model1_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate  Std. Error  t value\n",
      "imputed_new_buses                        0.020381662 0.002117618 9.624808\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.005938427 0.002829200 2.098977\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        6.294882e-22\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 3.581912e-02\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                           </td><td>0.0203816624978698          </td><td>0.0021176175266326          </td><td>9.62480818256184            </td><td>6.2948821992348e-22         </td><td>0.276632783066185           </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                           </td><td>0.00593842727766852         </td><td>0.00282920027340414         </td><td>2.09897734476157            </td><td>0.0358191243367423          </td><td>0.276632783066185           </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                                & 0.0203816624978698               & 0.0021176175266326               & 9.62480818256184                 & 6.2948821992348e-22              & 0.276632783066185                & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                & 0.00593842727766852              & 0.00282920027340414              & 2.09897734476157                 & 0.0358191243367423               & 0.276632783066185                & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                            | 0.0203816624978698           | 0.0021176175266326           | 9.62480818256184             | 6.2948821992348e-22          | 0.276632783066185            | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                            | 0.00593842727766852          | 0.00282920027340414          | 2.09897734476157             | 0.0358191243367423           | 0.276632783066185            | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate           \n",
       "imputed_new_buses                        2     0.0203816624978698 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.00593842727766852\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.0021176175266326  9.62480818256184\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00282920027340414 2.09897734476157\n",
       "                                         Pr(>|t|)            r2               \n",
       "imputed_new_buses                        6.2948821992348e-22 0.276632783066185\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0358191243367423  0.276632783066185\n",
       "                                         N       granularity                 \n",
       "imputed_new_buses                        1104348 rider/date/commute [Pre-HOV]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 1104348 rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model2_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                             Estimate  Std. Error    t value\n",
      "imputed_new_buses                         0.028970849 0.002807211 10.3201556\n",
      "imputed_new_buses:IsRouteSeattle_10_ride -0.002925051 0.003998815 -0.7314796\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        5.748150e-25\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 4.644866e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                        </td><td>0.028970849148144                                        </td><td>0.00280721050623915                                      </td><td>10.3201555721436                                         </td><td>5.748150334968e-25                                       </td><td>0.304062522412056                                        </td><td>471656                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                        </td><td>-0.00292505142036499                                     </td><td>0.00399881456320739                                      </td><td>-0.731479635809581                                       </td><td>0.464486602147099                                        </td><td>0.304062522412056                                        </td><td>471656                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                                                             & 0.028970849148144                                             & 0.00280721050623915                                           & 10.3201555721436                                              & 5.748150334968e-25                                            & 0.304062522412056                                             & 471656                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                             & -0.00292505142036499                                          & 0.00399881456320739                                           & -0.731479635809581                                            & 0.464486602147099                                             & 0.304062522412056                                             & 471656                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                                                         | 0.028970849148144                                         | 0.00280721050623915                                       | 10.3201555721436                                          | 5.748150334968e-25                                        | 0.304062522412056                                         | 471656                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                         | -0.00292505142036499                                      | 0.00399881456320739                                       | -0.731479635809581                                        | 0.464486602147099                                         | 0.304062522412056                                         | 471656                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate            \n",
       "imputed_new_buses                        3     0.028970849148144   \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     -0.00292505142036499\n",
       "                                         Std. Error          t value           \n",
       "imputed_new_buses                        0.00280721050623915 10.3201555721436  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00399881456320739 -0.731479635809581\n",
       "                                         Pr(>|t|)           r2               \n",
       "imputed_new_buses                        5.748150334968e-25 0.304062522412056\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.464486602147099  0.304062522412056\n",
       "                                         N     \n",
       "imputed_new_buses                        471656\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 471656\n",
       "                                         granularity                                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model3_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (first_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate  Std. Error  t value\n",
      "imputed_new_buses                        0.021145604 0.002379404 8.886932\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.007634302 0.003345403 2.282028\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        6.295277e-19\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 2.248798e-02\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.0211456043717674                                      </td><td>0.00237940431141981                                     </td><td>8.88693202339775                                        </td><td>6.29527683217756e-19                                    </td><td>0.287406420981424                                       </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.00763430242479268                                     </td><td>0.00334540290394017                                     </td><td>2.28202779874469                                        </td><td>0.0224879764426814                                      </td><td>0.287406420981424                                       </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.0211456043717674                                           & 0.00237940431141981                                          & 8.88693202339775                                             & 6.29527683217756e-19                                         & 0.287406420981424                                            & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.00763430242479268                                          & 0.00334540290394017                                          & 2.28202779874469                                             & 0.0224879764426814                                           & 0.287406420981424                                            & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.0211456043717674                                       | 0.00237940431141981                                      | 8.88693202339775                                         | 6.29527683217756e-19                                     | 0.287406420981424                                        | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.00763430242479268                                      | 0.00334540290394017                                      | 2.28202779874469                                         | 0.0224879764426814                                       | 0.287406420981424                                        | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate           \n",
       "imputed_new_buses                        4     0.0211456043717674 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00763430242479268\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00237940431141981 8.88693202339775\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00334540290394017 2.28202779874469\n",
       "                                         Pr(>|t|)             r2               \n",
       "imputed_new_buses                        6.29527683217756e-19 0.287406420981424\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0224879764426814   0.287406420981424\n",
       "                                         N     \n",
       "imputed_new_buses                        753890\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 753890\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model4_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.574771e-02 1.931180e-03 1.333263e+01 1.511593e-40 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>5                                                     </td><td>0.0257477137091702                                    </td><td>0.00193117977737595                                   </td><td>13.3326342843936                                      </td><td>1.51159273840049e-40                                  </td><td>0.255026901467857                                     </td><td>733928                                                </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 5                                                          & 0.0257477137091702                                         & 0.00193117977737595                                        & 13.3326342843936                                           & 1.51159273840049e-40                                       & 0.255026901467857                                          & 733928                                                     & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 5                                                      | 0.0257477137091702                                     | 0.00193117977737595                                    | 13.3326342843936                                       | 1.51159273840049e-40                                   | 0.255026901467857                                      | 733928                                                 | rider/date/commute [Pre-HOV; Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 5     0.0257477137091702 0.00193117977737595 13.3326342843936\n",
       "     Pr(>|t|)             r2                N     \n",
       "[1,] 1.51159273840049e-40 0.255026901467857 733928\n",
       "     granularity                                           \n",
       "[1,] rider/date/commute [Pre-HOV; Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model5_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride >= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.116723e-02 2.075529e-03 1.019847e+01 2.029192e-24 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>6                                                         </td><td>0.0211672276253699                                        </td><td>0.00207552929076805                                       </td><td>10.1984721292644                                          </td><td>2.02919245490518e-24                                      </td><td>0.321385221399999                                         </td><td>370670                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 6                                                              & 0.0211672276253699                                             & 0.00207552929076805                                            & 10.1984721292644                                               & 2.02919245490518e-24                                           & 0.321385221399999                                              & 370670                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 6                                                          | 0.0211672276253699                                         | 0.00207552929076805                                        | 10.1984721292644                                           | 2.02919245490518e-24                                       | 0.321385221399999                                          | 370670                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 6     0.0211672276253699 0.00207552929076805 10.1984721292644\n",
       "     Pr(>|t|)             r2                N     \n",
       "[1,] 2.02919245490518e-24 0.321385221399999 370670\n",
       "     granularity                                               \n",
       "[1,] rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model6_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride <= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=6,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                         </td><td>0.0236757651855375                                        </td><td>0.00142173916370504                                       </td><td>16.6526784869867                                          </td><td>2.94474161476437e-62                                      </td><td>0.276629897089897                                         </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                         </td><td>0.0203816624978698                                        </td><td>0.0021176175266326                                        </td><td>9.62480818256184                                          </td><td>6.2948821992348e-22                                       </td><td>0.276632783066185                                         </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                                                         </td><td>0.00593842727766852                                       </td><td>0.00282920027340414                                       </td><td>2.09897734476157                                          </td><td>0.0358191243367423                                        </td><td>0.276632783066185                                         </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                         </td><td>0.028970849148144                                         </td><td>0.00280721050623915                                       </td><td>10.3201555721436                                          </td><td>5.748150334968e-25                                        </td><td>0.304062522412056                                         </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                         </td><td>-0.00292505142036499                                      </td><td>0.00399881456320739                                       </td><td>-0.731479635809581                                        </td><td>0.464486602147099                                         </td><td>0.304062522412056                                         </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                         </td><td>0.0211456043717674                                        </td><td>0.00237940431141981                                       </td><td>8.88693202339775                                          </td><td>6.29527683217756e-19                                      </td><td>0.287406420981424                                         </td><td>753890                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                         </td><td>0.00763430242479268                                       </td><td>0.00334540290394017                                       </td><td>2.28202779874469                                          </td><td>0.0224879764426814                                        </td><td>0.287406420981424                                         </td><td>753890                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                                         </td><td>0.0257477137091702                                        </td><td>0.00193117977737595                                       </td><td>13.3326342843936                                          </td><td>1.51159273840049e-40                                      </td><td>0.255026901467857                                         </td><td>733928                                                    </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]    </td></tr>\n",
       "\t<tr><th scope=row></th><td>6                                                         </td><td>0.0211672276253699                                        </td><td>0.00207552929076805                                       </td><td>10.1984721292644                                          </td><td>2.02919245490518e-24                                      </td><td>0.321385221399999                                         </td><td>370670                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                              & 0.0236757651855375                                             & 0.00142173916370504                                            & 16.6526784869867                                               & 2.94474161476437e-62                                           & 0.276629897089897                                              & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 2                                                              & 0.0203816624978698                                             & 0.0021176175266326                                             & 9.62480818256184                                               & 6.2948821992348e-22                                            & 0.276632783066185                                              & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                                              & 0.00593842727766852                                            & 0.00282920027340414                                            & 2.09897734476157                                               & 0.0358191243367423                                             & 0.276632783066185                                              & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 3                                                              & 0.028970849148144                                              & 0.00280721050623915                                            & 10.3201555721436                                               & 5.748150334968e-25                                             & 0.304062522412056                                              & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                              & -0.00292505142036499                                           & 0.00399881456320739                                            & -0.731479635809581                                             & 0.464486602147099                                              & 0.304062522412056                                              & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses & 4                                                              & 0.0211456043717674                                             & 0.00237940431141981                                            & 8.88693202339775                                               & 6.29527683217756e-19                                           & 0.287406420981424                                              & 753890                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                              & 0.00763430242479268                                            & 0.00334540290394017                                            & 2.28202779874469                                               & 0.0224879764426814                                             & 0.287406420981424                                              & 753890                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\t & 5                                                              & 0.0257477137091702                                             & 0.00193117977737595                                            & 13.3326342843936                                               & 1.51159273840049e-40                                           & 0.255026901467857                                              & 733928                                                         & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}    \\\\\n",
       "\t & 6                                                              & 0.0211672276253699                                             & 0.00207552929076805                                            & 10.1984721292644                                               & 2.02919245490518e-24                                           & 0.321385221399999                                              & 370670                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                          | 0.0236757651855375                                         | 0.00142173916370504                                        | 16.6526784869867                                           | 2.94474161476437e-62                                       | 0.276629897089897                                          | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 2                                                          | 0.0203816624978698                                         | 0.0021176175266326                                         | 9.62480818256184                                           | 6.2948821992348e-22                                        | 0.276632783066185                                          | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                                                          | 0.00593842727766852                                        | 0.00282920027340414                                        | 2.09897734476157                                           | 0.0358191243367423                                         | 0.276632783066185                                          | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 3                                                          | 0.028970849148144                                          | 0.00280721050623915                                        | 10.3201555721436                                           | 5.748150334968e-25                                         | 0.304062522412056                                          | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                          | -0.00292505142036499                                       | 0.00399881456320739                                        | -0.731479635809581                                         | 0.464486602147099                                          | 0.304062522412056                                          | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses | 4                                                          | 0.0211456043717674                                         | 0.00237940431141981                                        | 8.88693202339775                                           | 6.29527683217756e-19                                       | 0.287406420981424                                          | 753890                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                          | 0.00763430242479268                                        | 0.00334540290394017                                        | 2.28202779874469                                           | 0.0224879764426814                                         | 0.287406420981424                                          | 753890                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "|  | 5                                                          | 0.0257477137091702                                         | 0.00193117977737595                                        | 13.3326342843936                                           | 1.51159273840049e-40                                       | 0.255026901467857                                          | 733928                                                     | rider/date/commute [Pre-HOV; Seattle preferred riders]     |\n",
       "|  | 6                                                          | 0.0211672276253699                                         | 0.00207552929076805                                        | 10.1984721292644                                           | 2.02919245490518e-24                                       | 0.321385221399999                                          | 370670                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate            \n",
       "                                         1     0.0236757651855375  \n",
       "imputed_new_buses                        2     0.0203816624978698  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.00593842727766852 \n",
       "imputed_new_buses                        3     0.028970849148144   \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     -0.00292505142036499\n",
       "imputed_new_buses                        4     0.0211456043717674  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00763430242479268 \n",
       "                                         5     0.0257477137091702  \n",
       "                                         6     0.0211672276253699  \n",
       "                                         Std. Error          t value           \n",
       "                                         0.00142173916370504 16.6526784869867  \n",
       "imputed_new_buses                        0.0021176175266326  9.62480818256184  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00282920027340414 2.09897734476157  \n",
       "imputed_new_buses                        0.00280721050623915 10.3201555721436  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00399881456320739 -0.731479635809581\n",
       "imputed_new_buses                        0.00237940431141981 8.88693202339775  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00334540290394017 2.28202779874469  \n",
       "                                         0.00193117977737595 13.3326342843936  \n",
       "                                         0.00207552929076805 10.1984721292644  \n",
       "                                         Pr(>|t|)             r2               \n",
       "                                         2.94474161476437e-62 0.276629897089897\n",
       "imputed_new_buses                        6.2948821992348e-22  0.276632783066185\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0358191243367423   0.276632783066185\n",
       "imputed_new_buses                        5.748150334968e-25   0.304062522412056\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.464486602147099    0.304062522412056\n",
       "imputed_new_buses                        6.29527683217756e-19 0.287406420981424\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0224879764426814   0.287406420981424\n",
       "                                         1.51159273840049e-40 0.255026901467857\n",
       "                                         2.02919245490518e-24 0.321385221399999\n",
       "                                         N      \n",
       "                                         1104348\n",
       "imputed_new_buses                        1104348\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 1104348\n",
       "imputed_new_buses                        471656 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 471656 \n",
       "imputed_new_buses                        753890 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 753890 \n",
       "                                         733928 \n",
       "                                         370670 \n",
       "                                         granularity                                               \n",
       "                                         rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "                                         rider/date/commute [Pre-HOV; Seattle preferred riders]    \n",
       "                                         rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "rbind( table2_model1_pre_HOV,\n",
    "       table2_model2_pre_HOV,\n",
    "       table2_model3_pre_HOV,\n",
    "       table2_model4_pre_HOV,\n",
    "       table2_model5_pre_HOV,\n",
    "       table2_model6_pre_HOV)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.838344e-02 1.312352e-03 1.400801e+01 1.400102e-44 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                   </td><td>0.0183834420658064  </td><td>0.00131235215593952 </td><td>14.0080099557162    </td><td>1.40010244000293e-44</td><td>0.3044796455947     </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                    & 0.0183834420658064   & 0.00131235215593952  & 14.0080099557162     & 1.40010244000293e-44 & 0.3044796455947      & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                    | 0.0183834420658064   | 0.00131235215593952  | 14.0080099557162     | 1.40010244000293e-44 | 0.3044796455947      | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 1     0.0183834420658064 0.00131235215593952 14.0080099557162\n",
       "     Pr(>|t|)             r2              N       granularity       \n",
       "[1,] 1.40010244000293e-44 0.3044796455947 1792156 rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=1,\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "post_hov:IsRouteSeattle_10_ride                  0.009638937 0.002816472\n",
      "is_peak_10_ride                                  0.009724509 0.002073547\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride           0.027822920 0.002505539\n",
      "post_hov:is_peak_10_ride                        -0.024136687 0.003280753\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride  0.012018584 0.003997005\n",
      "                                                  t value     Pr(>|t|)\n",
      "post_hov:IsRouteSeattle_10_ride                  3.422344 6.208510e-04\n",
      "is_peak_10_ride                                  4.689794 2.735002e-06\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          11.104564 1.194544e-28\n",
      "post_hov:is_peak_10_ride                        -7.357056 1.880901e-13\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride  3.006897 2.639326e-03\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                   </td><td>0.00963893724650586 </td><td>0.00281647234222826 </td><td>3.42234400884618    </td><td>0.000620850962943762</td><td>0.304835246011862   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                   </td><td>0.00972450904195021 </td><td>0.00207354709992748 </td><td>4.68979414178261    </td><td>2.73500153213254e-06</td><td>0.304835246011862   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                   </td><td>0.0278229201357811  </td><td>0.00250553908896106 </td><td>11.1045643863086    </td><td>1.19454364868092e-28</td><td>0.304835246011862   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                   </td><td>-0.0241366870506926 </td><td>0.00328075346524461 </td><td>-7.3570560258154    </td><td>1.88090135317251e-13</td><td>0.304835246011862   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                   </td><td>0.0120185839852569  </td><td>0.00399700518418931 </td><td>3.00689727218718    </td><td>0.00263932594521174 </td><td>0.304835246011862   </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                    & 0.00963893724650586  & 0.00281647234222826  & 3.42234400884618     & 0.000620850962943762 & 0.304835246011862    & 1792156              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                    & 0.00972450904195021  & 0.00207354709992748  & 4.68979414178261     & 2.73500153213254e-06 & 0.304835246011862    & 1792156              & rider/date/commute  \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                    & 0.0278229201357811   & 0.00250553908896106  & 11.1045643863086     & 1.19454364868092e-28 & 0.304835246011862    & 1792156              & rider/date/commute  \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                    & -0.0241366870506926  & 0.00328075346524461  & -7.3570560258154     & 1.88090135317251e-13 & 0.304835246011862    & 1792156              & rider/date/commute  \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                    & 0.0120185839852569   & 0.00399700518418931  & 3.00689727218718     & 0.00263932594521174  & 0.304835246011862    & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                    | 0.00963893724650586  | 0.00281647234222826  | 3.42234400884618     | 0.000620850962943762 | 0.304835246011862    | 1792156              | rider/date/commute   |\n",
       "| is_peak_10_ride | 2                    | 0.00972450904195021  | 0.00207354709992748  | 4.68979414178261     | 2.73500153213254e-06 | 0.304835246011862    | 1792156              | rider/date/commute   |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                    | 0.0278229201357811   | 0.00250553908896106  | 11.1045643863086     | 1.19454364868092e-28 | 0.304835246011862    | 1792156              | rider/date/commute   |\n",
       "| post_hov:is_peak_10_ride | 2                    | -0.0241366870506926  | 0.00328075346524461  | -7.3570560258154     | 1.88090135317251e-13 | 0.304835246011862    | 1792156              | rider/date/commute   |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                    | 0.0120185839852569   | 0.00399700518418931  | 3.00689727218718     | 0.00263932594521174  | 0.304835246011862    | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate           \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.00963893724650586\n",
       "is_peak_10_ride                                 2     0.00972450904195021\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.0278229201357811 \n",
       "post_hov:is_peak_10_ride                        2     -0.0241366870506926\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.0120185839852569 \n",
       "                                                Std. Error         \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00281647234222826\n",
       "is_peak_10_ride                                 0.00207354709992748\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.00250553908896106\n",
       "post_hov:is_peak_10_ride                        0.00328075346524461\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00399700518418931\n",
       "                                                t value         \n",
       "post_hov:IsRouteSeattle_10_ride                 3.42234400884618\n",
       "is_peak_10_ride                                 4.68979414178261\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          11.1045643863086\n",
       "post_hov:is_peak_10_ride                        -7.3570560258154\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 3.00689727218718\n",
       "                                                Pr(>|t|)            \n",
       "post_hov:IsRouteSeattle_10_ride                 0.000620850962943762\n",
       "is_peak_10_ride                                 2.73500153213254e-06\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          1.19454364868092e-28\n",
       "post_hov:is_peak_10_ride                        1.88090135317251e-13\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00263932594521174 \n",
       "                                                r2                N      \n",
       "post_hov:IsRouteSeattle_10_ride                 0.304835246011862 1792156\n",
       "is_peak_10_ride                                 0.304835246011862 1792156\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.304835246011862 1792156\n",
       "post_hov:is_peak_10_ride                        0.304835246011862 1792156\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.304835246011862 1792156\n",
       "                                                granularity       \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute\n",
       "is_peak_10_ride                                 rider/date/commute\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute\n",
       "post_hov:is_peak_10_ride                        rider/date/commute\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\",\n",
    "                                        \"is_peak_10_ride\",\n",
    "                                        \"IsRouteSeattle_10_ride:is_peak_10_ride\",\n",
    "                                        \"post_hov:is_peak_10_ride\",\n",
    "                                        \"post_hov:IsRouteSeattle_10_ride:is_peak_10_ride\"\n",
    "                                ),\n",
    "                        model=2,\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.607587e-02 1.906387e-03 8.432639e+00 3.385329e-17 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3                                              </td><td>0.0160758731670565                             </td><td>0.00190638697207982                            </td><td>8.43263901951561                               </td><td>3.38532917887041e-17                           </td><td>0.326504398075457                              </td><td>762048                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 3                                                   & 0.0160758731670565                                  & 0.00190638697207982                                 & 8.43263901951561                                    & 3.38532917887041e-17                                & 0.326504398075457                                   & 762048                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 3                                               | 0.0160758731670565                              | 0.00190638697207982                             | 8.43263901951561                                | 3.38532917887041e-17                            | 0.326504398075457                               | 762048                                          | rider/date/commute [first stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 3     0.0160758731670565 0.00190638697207982 8.43263901951561\n",
       "     Pr(>|t|)             r2                N     \n",
       "[1,] 3.38532917887041e-17 0.326504398075457 762048\n",
       "     granularity                                    \n",
       "[1,] rider/date/commute [first stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=3,\n",
    "                        granularity=\"rider/date/commute [first stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.930788e-02 1.549990e-03 1.245678e+01 1.291005e-35 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>4                                             </td><td>0.0193078817255487                            </td><td>0.00154999001960853                           </td><td>12.4567780961745                              </td><td>1.29100465638727e-35                          </td><td>0.316377266684956                             </td><td>1218882                                       </td><td>rider/date/commute [last stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 4                                                  & 0.0193078817255487                                 & 0.00154999001960853                                & 12.4567780961745                                   & 1.29100465638727e-35                               & 0.316377266684956                                  & 1218882                                            & rider/date/commute {[}last stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 4                                              | 0.0193078817255487                             | 0.00154999001960853                            | 12.4567780961745                               | 1.29100465638727e-35                           | 0.316377266684956                              | 1218882                                        | rider/date/commute [last stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 4     0.0193078817255487 0.00154999001960853 12.4567780961745\n",
       "     Pr(>|t|)             r2                N      \n",
       "[1,] 1.29100465638727e-35 0.316377266684956 1218882\n",
       "     granularity                                   \n",
       "[1,] rider/date/commute [last stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=4,\n",
    "                        granularity=\"rider/date/commute [last stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.004685415 0.002114822 2.215512444 0.026725241 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>5                  </td><td>0.00468541479446172</td><td>0.00211482215206419</td><td>2.21551244386602   </td><td>0.0267252412082117 </td><td>0.319069912690138  </td><td>679992             </td><td>ride/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 5                   & 0.00468541479446172 & 0.00211482215206419 & 2.21551244386602    & 0.0267252412082117  & 0.319069912690138   & 679992              & ride/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 5                   | 0.00468541479446172 | 0.00211482215206419 | 2.21551244386602    | 0.0267252412082117  | 0.319069912690138   | 679992              | ride/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error          t value         \n",
       "[1,] 5     0.00468541479446172 0.00211482215206419 2.21551244386602\n",
       "     Pr(>|t|)           r2                N      granularity      \n",
       "[1,] 0.0267252412082117 0.319069912690138 679992 ride/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "(table3_model5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                        date < as.Date(\"2016-07-01\")],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=5,\n",
    "                        granularity=\"ride/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                              </td><td>0.0183834420658064                             </td><td>0.00131235215593952                            </td><td>14.0080099557162                               </td><td>1.40010244000293e-44                           </td><td>0.3044796455947                                </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.00963893724650586                            </td><td>0.00281647234222826                            </td><td>3.42234400884618                               </td><td>0.000620850962943762                           </td><td>0.304835246011862                              </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.00972450904195021                            </td><td>0.00207354709992748                            </td><td>4.68979414178261                               </td><td>2.73500153213254e-06                           </td><td>0.304835246011862                              </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.0278229201357811                             </td><td>0.00250553908896106                            </td><td>11.1045643863086                               </td><td>1.19454364868092e-28                           </td><td>0.304835246011862                              </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                                              </td><td>-0.0241366870506926                            </td><td>0.00328075346524461                            </td><td>-7.3570560258154                               </td><td>1.88090135317251e-13                           </td><td>0.304835246011862                              </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.0120185839852569                             </td><td>0.00399700518418931                            </td><td>3.00689727218718                               </td><td>0.00263932594521174                            </td><td>0.304835246011862                              </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row></th><td>3                                              </td><td>0.0160758731670565                             </td><td>0.00190638697207982                            </td><td>8.43263901951561                               </td><td>3.38532917887041e-17                           </td><td>0.326504398075457                              </td><td>762048                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row></th><td>4                                              </td><td>0.0193078817255487                             </td><td>0.00154999001960853                            </td><td>12.4567780961745                               </td><td>1.29100465638727e-35                           </td><td>0.316377266684956                              </td><td>1218882                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                              </td><td>0.00468541479446172                            </td><td>0.00211482215206419                            </td><td>2.21551244386602                               </td><td>0.0267252412082117                             </td><td>0.319069912690138                              </td><td>679992                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                               & 0.0183834420658064                              & 0.00131235215593952                             & 14.0080099557162                                & 1.40010244000293e-44                            & 0.3044796455947                                 & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                                               & 0.00963893724650586                             & 0.00281647234222826                             & 3.42234400884618                                & 0.000620850962943762                            & 0.304835246011862                               & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.00972450904195021                             & 0.00207354709992748                             & 4.68979414178261                                & 2.73500153213254e-06                            & 0.304835246011862                               & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.0278229201357811                              & 0.00250553908896106                             & 11.1045643863086                                & 1.19454364868092e-28                            & 0.304835246011862                               & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                                               & -0.0241366870506926                             & 0.00328075346524461                             & -7.3570560258154                                & 1.88090135317251e-13                            & 0.304835246011862                               & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.0120185839852569                              & 0.00399700518418931                             & 3.00689727218718                                & 0.00263932594521174                             & 0.304835246011862                               & 1792156                                         & rider/date/commute                             \\\\\n",
       "\t & 3                                                   & 0.0160758731670565                                  & 0.00190638697207982                                 & 8.43263901951561                                    & 3.38532917887041e-17                                & 0.326504398075457                                   & 762048                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\t & 4                                                   & 0.0193078817255487                                  & 0.00154999001960853                                 & 12.4567780961745                                    & 1.29100465638727e-35                                & 0.316377266684956                                   & 1218882                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\t & 5                                               & 0.00468541479446172                             & 0.00211482215206419                             & 2.21551244386602                                & 0.0267252412082117                              & 0.319069912690138                               & 679992                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                               | 0.0183834420658064                              | 0.00131235215593952                             | 14.0080099557162                                | 1.40010244000293e-44                            | 0.3044796455947                                 | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                                               | 0.00963893724650586                             | 0.00281647234222826                             | 3.42234400884618                                | 0.000620850962943762                            | 0.304835246011862                               | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.00972450904195021                             | 0.00207354709992748                             | 4.68979414178261                                | 2.73500153213254e-06                            | 0.304835246011862                               | 1792156                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.0278229201357811                              | 0.00250553908896106                             | 11.1045643863086                                | 1.19454364868092e-28                            | 0.304835246011862                               | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:is_peak_10_ride | 2                                               | -0.0241366870506926                             | 0.00328075346524461                             | -7.3570560258154                                | 1.88090135317251e-13                            | 0.304835246011862                               | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.0120185839852569                              | 0.00399700518418931                             | 3.00689727218718                                | 0.00263932594521174                             | 0.304835246011862                               | 1792156                                         | rider/date/commute                              |\n",
       "|  | 3                                               | 0.0160758731670565                              | 0.00190638697207982                             | 8.43263901951561                                | 3.38532917887041e-17                            | 0.326504398075457                               | 762048                                          | rider/date/commute [first stop prefered riders] |\n",
       "|  | 4                                               | 0.0193078817255487                              | 0.00154999001960853                             | 12.4567780961745                                | 1.29100465638727e-35                            | 0.316377266684956                               | 1218882                                         | rider/date/commute [last stop prefered riders]  |\n",
       "|  | 5                                               | 0.00468541479446172                             | 0.00211482215206419                             | 2.21551244386602                                | 0.0267252412082117                              | 0.319069912690138                               | 679992                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate           \n",
       "                                                1     0.0183834420658064 \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.00963893724650586\n",
       "is_peak_10_ride                                 2     0.00972450904195021\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.0278229201357811 \n",
       "post_hov:is_peak_10_ride                        2     -0.0241366870506926\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.0120185839852569 \n",
       "                                                3     0.0160758731670565 \n",
       "                                                4     0.0193078817255487 \n",
       "                                                5     0.00468541479446172\n",
       "                                                Std. Error         \n",
       "                                                0.00131235215593952\n",
       "post_hov:IsRouteSeattle_10_ride                 0.00281647234222826\n",
       "is_peak_10_ride                                 0.00207354709992748\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.00250553908896106\n",
       "post_hov:is_peak_10_ride                        0.00328075346524461\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00399700518418931\n",
       "                                                0.00190638697207982\n",
       "                                                0.00154999001960853\n",
       "                                                0.00211482215206419\n",
       "                                                t value         \n",
       "                                                14.0080099557162\n",
       "post_hov:IsRouteSeattle_10_ride                 3.42234400884618\n",
       "is_peak_10_ride                                 4.68979414178261\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          11.1045643863086\n",
       "post_hov:is_peak_10_ride                        -7.3570560258154\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 3.00689727218718\n",
       "                                                8.43263901951561\n",
       "                                                12.4567780961745\n",
       "                                                2.21551244386602\n",
       "                                                Pr(>|t|)            \n",
       "                                                1.40010244000293e-44\n",
       "post_hov:IsRouteSeattle_10_ride                 0.000620850962943762\n",
       "is_peak_10_ride                                 2.73500153213254e-06\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          1.19454364868092e-28\n",
       "post_hov:is_peak_10_ride                        1.88090135317251e-13\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00263932594521174 \n",
       "                                                3.38532917887041e-17\n",
       "                                                1.29100465638727e-35\n",
       "                                                0.0267252412082117  \n",
       "                                                r2                N      \n",
       "                                                0.3044796455947   1792156\n",
       "post_hov:IsRouteSeattle_10_ride                 0.304835246011862 1792156\n",
       "is_peak_10_ride                                 0.304835246011862 1792156\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.304835246011862 1792156\n",
       "post_hov:is_peak_10_ride                        0.304835246011862 1792156\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.304835246011862 1792156\n",
       "                                                0.326504398075457 762048 \n",
       "                                                0.316377266684956 1218882\n",
       "                                                0.319069912690138 679992 \n",
       "                                                granularity                                    \n",
       "                                                rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute                             \n",
       "post_hov:is_peak_10_ride                        rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute                             \n",
       "                                                rider/date/commute [first stop prefered riders]\n",
       "                                                rider/date/commute [last stop prefered riders] \n",
       "                                                ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "rbind( table3_model1,\n",
    "       table3_model2,\n",
    "       table3_model3,\n",
    "       table3_model4,\n",
    "       table3_model5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.986274e-02 5.995035e-03 4.981245e+00 6.327656e-07 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                                                </td><td>0.0298627367907546                               </td><td>0.00599503457828382                              </td><td>4.98124512891522                                 </td><td>6.32765550056834e-07                             </td><td>0.323794699565868                                </td><td>105112                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{llllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                                     & 0.0298627367907546                                    & 0.00599503457828382                                   & 4.98124512891522                                      & 6.32765550056834e-07                                  & 0.323794699565868                                     & 105112                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1                                                 | 0.0298627367907546                                | 0.00599503457828382                               | 4.98124512891522                                  | 6.32765550056834e-07                              | 0.323794699565868                                 | 105112                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 1     0.0298627367907546 0.00599503457828382 4.98124512891522\n",
       "     Pr(>|t|)             r2                N     \n",
       "[1,] 6.32765550056834e-07 0.323794699565868 105112\n",
       "     granularity                                      \n",
       "[1,] rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV) & (single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                           \"f_favorite_route\" ),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                         Estimate  Std. Error   t value\n",
      "imputed_new_buses                     -0.01463719 0.001969868 -7.430543\n",
      "imputed_new_buses:single_stop_10_ride  0.01139417 0.004479672  2.543529\n",
      "                                          Pr(>|t|)\n",
      "imputed_new_buses                     1.082305e-13\n",
      "imputed_new_buses:single_stop_10_ride 1.097404e-02\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                   </td><td>-0.0146371912264553 </td><td>0.00196986842779907 </td><td>-7.43054257832304   </td><td>1.08230472725702e-13</td><td>0.283604099270915   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                   </td><td>0.0113941737714081  </td><td>0.00447967203922432 </td><td>2.54352856004634    </td><td>0.0109740436594509  </td><td>0.283604099270915   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                    & -0.0146371912264553  & 0.00196986842779907  & -7.43054257832304    & 1.08230472725702e-13 & 0.283604099270915    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                    & 0.0113941737714081   & 0.00447967203922432  & 2.54352856004634     & 0.0109740436594509   & 0.283604099270915    & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                    | -0.0146371912264553  | 0.00196986842779907  | -7.43054257832304    | 1.08230472725702e-13 | 0.283604099270915    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                    | 0.0113941737714081   | 0.00447967203922432  | 2.54352856004634     | 0.0109740436594509   | 0.283604099270915    | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model Estimate           \n",
       "imputed_new_buses                     2     -0.0146371912264553\n",
       "imputed_new_buses:single_stop_10_ride 2     0.0113941737714081 \n",
       "                                      Std. Error          t value          \n",
       "imputed_new_buses                     0.00196986842779907 -7.43054257832304\n",
       "imputed_new_buses:single_stop_10_ride 0.00447967203922432 2.54352856004634 \n",
       "                                      Pr(>|t|)             r2               \n",
       "imputed_new_buses                     1.08230472725702e-13 0.283604099270915\n",
       "imputed_new_buses:single_stop_10_ride 0.0109740436594509   0.283604099270915\n",
       "                                      N       granularity       \n",
       "imputed_new_buses                     1104348 rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride 1104348 rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                Estimate  Std. Error   t value\n",
      "imputed_new_buses                            -0.30481791 0.040271688 -7.569037\n",
      "Is405North_10_ride:I405HOV                    0.00925924 0.005887006  1.572827\n",
      "imputed_new_buses:I405HOV                     0.29846485 0.040054958  7.451384\n",
      "imputed_new_buses:Is405North_10_ride          0.16019783 0.056646905  2.828007\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.19467986 0.056641250 -3.437069\n",
      "                                                 Pr(>|t|)\n",
      "imputed_new_buses                            3.762889e-14\n",
      "Is405North_10_ride:I405HOV                   1.157592e-01\n",
      "imputed_new_buses:I405HOV                    9.243320e-14\n",
      "imputed_new_buses:Is405North_10_ride         4.683966e-03\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV 5.880685e-04\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                   </td><td>-0.304817914528539  </td><td>0.0402716879334351  </td><td>-7.56903745957636   </td><td>3.76288935610978e-14</td><td>0.283702478067186   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                   </td><td>0.00925924046454574 </td><td>0.00588700606363359 </td><td>1.57282672456273    </td><td>0.115759232278501   </td><td>0.283702478067186   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                   </td><td>0.298464852053449   </td><td>0.0400549575685847  </td><td>7.45138355326925    </td><td>9.24331971089394e-14</td><td>0.283702478067186   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                   </td><td>0.160197831409656   </td><td>0.0566469047270118  </td><td>2.82800679369276    </td><td>0.0046839655485875  </td><td>0.283702478067186   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                   </td><td>-0.194679856895537  </td><td>0.0566412499958205  </td><td>-3.43706851296365   </td><td>0.000588068486048824</td><td>0.283702478067186   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                    & -0.304817914528539   & 0.0402716879334351   & -7.56903745957636    & 3.76288935610978e-14 & 0.283702478067186    & 1104348              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                    & 0.00925924046454574  & 0.00588700606363359  & 1.57282672456273     & 0.115759232278501    & 0.283702478067186    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                    & 0.298464852053449    & 0.0400549575685847   & 7.45138355326925     & 9.24331971089394e-14 & 0.283702478067186    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                    & 0.160197831409656    & 0.0566469047270118   & 2.82800679369276     & 0.0046839655485875   & 0.283702478067186    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                    & -0.194679856895537   & 0.0566412499958205   & -3.43706851296365    & 0.000588068486048824 & 0.283702478067186    & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                    | -0.304817914528539   | 0.0402716879334351   | -7.56903745957636    | 3.76288935610978e-14 | 0.283702478067186    | 1104348              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 3                    | 0.00925924046454574  | 0.00588700606363359  | 1.57282672456273     | 0.115759232278501    | 0.283702478067186    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:I405HOV | 3                    | 0.298464852053449    | 0.0400549575685847   | 7.45138355326925     | 9.24331971089394e-14 | 0.283702478067186    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                    | 0.160197831409656    | 0.0566469047270118   | 2.82800679369276     | 0.0046839655485875   | 0.283702478067186    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                    | -0.194679856895537   | 0.0566412499958205   | -3.43706851296365    | 0.000588068486048824 | 0.283702478067186    | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model Estimate           \n",
       "imputed_new_buses                            3     -0.304817914528539 \n",
       "Is405North_10_ride:I405HOV                   3     0.00925924046454574\n",
       "imputed_new_buses:I405HOV                    3     0.298464852053449  \n",
       "imputed_new_buses:Is405North_10_ride         3     0.160197831409656  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.194679856895537 \n",
       "                                             Std. Error         \n",
       "imputed_new_buses                            0.0402716879334351 \n",
       "Is405North_10_ride:I405HOV                   0.00588700606363359\n",
       "imputed_new_buses:I405HOV                    0.0400549575685847 \n",
       "imputed_new_buses:Is405North_10_ride         0.0566469047270118 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0566412499958205 \n",
       "                                             t value          \n",
       "imputed_new_buses                            -7.56903745957636\n",
       "Is405North_10_ride:I405HOV                   1.57282672456273 \n",
       "imputed_new_buses:I405HOV                    7.45138355326925 \n",
       "imputed_new_buses:Is405North_10_ride         2.82800679369276 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -3.43706851296365\n",
       "                                             Pr(>|t|)            \n",
       "imputed_new_buses                            3.76288935610978e-14\n",
       "Is405North_10_ride:I405HOV                   0.115759232278501   \n",
       "imputed_new_buses:I405HOV                    9.24331971089394e-14\n",
       "imputed_new_buses:Is405North_10_ride         0.0046839655485875  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.000588068486048824\n",
       "                                             r2                N      \n",
       "imputed_new_buses                            0.283702478067186 1104348\n",
       "Is405North_10_ride:I405HOV                   0.283702478067186 1104348\n",
       "imputed_new_buses:I405HOV                    0.283702478067186 1104348\n",
       "imputed_new_buses:Is405North_10_ride         0.283702478067186 1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.283702478067186 1104348\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                   Estimate  Std. Error\n",
      "imputed_new_buses                              -0.007277495 0.002153941\n",
      "imputed_new_buses:single_stop_10_ride           0.018522973 0.005816232\n",
      "Is405North_10_ride:I405HOV                      0.020613972 0.004658028\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.036414949 0.003749027\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.004992022 0.007387082\n",
      "                                                  t value     Pr(>|t|)\n",
      "imputed_new_buses                              -3.3786883 7.283505e-04\n",
      "imputed_new_buses:single_stop_10_ride           3.1847031 1.449066e-03\n",
      "Is405North_10_ride:I405HOV                      4.4254721 9.624081e-06\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -9.7131731 2.655035e-22\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.6757773 4.991822e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                   </td><td>-0.00727749548067217</td><td>0.00215394105342945 </td><td>-3.37868832068785   </td><td>0.000728350457894284</td><td>0.283667124529281   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                   </td><td>0.0185229731657398  </td><td>0.0058162323422483  </td><td>3.1847030991509     </td><td>0.00144906613064094 </td><td>0.283667124529281   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.0206139717882291  </td><td>0.00465802778346495 </td><td>4.42547205523431    </td><td>9.62408100455572e-06</td><td>0.283667124529281   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.0364149490091043 </td><td>0.003749027088264   </td><td>-9.71317308511803   </td><td>2.65503453034899e-22</td><td>0.283667124529281   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.00499202238631069</td><td>0.00738708166419208 </td><td>-0.675777338500111  </td><td>0.499182166204885   </td><td>0.283667124529281   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                    & -0.00727749548067217 & 0.00215394105342945  & -3.37868832068785    & 0.000728350457894284 & 0.283667124529281    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                    & 0.0185229731657398   & 0.0058162323422483   & 3.1847030991509      & 0.00144906613064094  & 0.283667124529281    & 1104348              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                    & 0.0206139717882291   & 0.00465802778346495  & 4.42547205523431     & 9.62408100455572e-06 & 0.283667124529281    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                    & -0.0364149490091043  & 0.003749027088264    & -9.71317308511803    & 2.65503453034899e-22 & 0.283667124529281    & 1104348              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                    & -0.00499202238631069 & 0.00738708166419208  & -0.675777338500111   & 0.499182166204885    & 0.283667124529281    & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                    | -0.00727749548067217 | 0.00215394105342945  | -3.37868832068785    | 0.000728350457894284 | 0.283667124529281    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                    | 0.0185229731657398   | 0.0058162323422483   | 3.1847030991509      | 0.00144906613064094  | 0.283667124529281    | 1104348              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 4                    | 0.0206139717882291   | 0.00465802778346495  | 4.42547205523431     | 9.62408100455572e-06 | 0.283667124529281    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                    | -0.0364149490091043  | 0.003749027088264    | -9.71317308511803    | 2.65503453034899e-22 | 0.283667124529281    | 1104348              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                    | -0.00499202238631069 | 0.00738708166419208  | -0.675777338500111   | 0.499182166204885    | 0.283667124529281    | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model Estimate            \n",
       "imputed_new_buses                              4     -0.00727749548067217\n",
       "imputed_new_buses:single_stop_10_ride          4     0.0185229731657398  \n",
       "Is405North_10_ride:I405HOV                     4     0.0206139717882291  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.0364149490091043 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     -0.00499202238631069\n",
       "                                               Std. Error         \n",
       "imputed_new_buses                              0.00215394105342945\n",
       "imputed_new_buses:single_stop_10_ride          0.0058162323422483 \n",
       "Is405North_10_ride:I405HOV                     0.00465802778346495\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.003749027088264  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.00738708166419208\n",
       "                                               t value           \n",
       "imputed_new_buses                              -3.37868832068785 \n",
       "imputed_new_buses:single_stop_10_ride          3.1847030991509   \n",
       "Is405North_10_ride:I405HOV                     4.42547205523431  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -9.71317308511803 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV -0.675777338500111\n",
       "                                               Pr(>|t|)            \n",
       "imputed_new_buses                              0.000728350457894284\n",
       "imputed_new_buses:single_stop_10_ride          0.00144906613064094 \n",
       "Is405North_10_ride:I405HOV                     9.62408100455572e-06\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   2.65503453034899e-22\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.499182166204885   \n",
       "                                               r2                N      \n",
       "imputed_new_buses                              0.283667124529281 1104348\n",
       "imputed_new_buses:single_stop_10_ride          0.283667124529281 1104348\n",
       "Is405North_10_ride:I405HOV                     0.283667124529281 1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.283667124529281 1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.283667124529281 1104348\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                     Estimate\n",
      "imputed_new_buses                                                -0.008466478\n",
      "imputed_new_buses:single_stop_10_ride                             0.030070865\n",
      "Is405North_10_ride:I405HOV                                        0.013857850\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.026787848\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    0.036485091\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.062660671\n",
      "                                                                  Std. Error\n",
      "imputed_new_buses                                                0.002172726\n",
      "imputed_new_buses:single_stop_10_ride                            0.006442174\n",
      "Is405North_10_ride:I405HOV                                       0.004931881\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.004403195\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.012392012\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.015031092\n",
      "                                                                   t value\n",
      "imputed_new_buses                                                -3.896707\n",
      "imputed_new_buses:single_stop_10_ride                             4.667813\n",
      "Is405North_10_ride:I405HOV                                        2.809851\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -6.083730\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    2.944243\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.168737\n",
      "                                                                     Pr(>|t|)\n",
      "imputed_new_buses                                                9.751531e-05\n",
      "imputed_new_buses:single_stop_10_ride                            3.044583e-06\n",
      "Is405North_10_ride:I405HOV                                       4.956535e-03\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     1.174567e-09\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.237529e-03\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 3.063153e-05\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                   </td><td>-0.00846647791645789</td><td>0.00217272646754832 </td><td>-3.89670676125714   </td><td>9.75153108461107e-05</td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                   </td><td>0.0300708654282957  </td><td>0.00644217422026693 </td><td>4.66781313266776    </td><td>3.04458256770485e-06</td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0138578502605138  </td><td>0.00493188121293141 </td><td>2.80985077746368    </td><td>0.00495653461378253 </td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0267878477100719 </td><td>0.00440319478892845 </td><td>-6.08372988118268   </td><td>1.17456732903453e-09</td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0364850905162761  </td><td>0.0123920124217862  </td><td>2.94424257129796    </td><td>0.00323752890842181 </td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0626606713808674 </td><td>0.0150310920861259  </td><td>-4.1687371098408    </td><td>3.0631532761509e-05 </td><td>0.283678398915836   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                    & -0.00846647791645789 & 0.00217272646754832  & -3.89670676125714    & 9.75153108461107e-05 & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                    & 0.0300708654282957   & 0.00644217422026693  & 4.66781313266776     & 3.04458256770485e-06 & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                    & 0.0138578502605138   & 0.00493188121293141  & 2.80985077746368     & 0.00495653461378253  & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0267878477100719  & 0.00440319478892845  & -6.08372988118268    & 1.17456732903453e-09 & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & 0.0364850905162761   & 0.0123920124217862   & 2.94424257129796     & 0.00323752890842181  & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0626606713808674  & 0.0150310920861259   & -4.1687371098408     & 3.0631532761509e-05  & 0.283678398915836    & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                    | -0.00846647791645789 | 0.00217272646754832  | -3.89670676125714    | 9.75153108461107e-05 | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                    | 0.0300708654282957   | 0.00644217422026693  | 4.66781313266776     | 3.04458256770485e-06 | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 5                    | 0.0138578502605138   | 0.00493188121293141  | 2.80985077746368     | 0.00495653461378253  | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                    | -0.0267878477100719  | 0.00440319478892845  | -6.08372988118268    | 1.17456732903453e-09 | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | 0.0364850905162761   | 0.0123920124217862   | 2.94424257129796     | 0.00323752890842181  | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | -0.0626606713808674  | 0.0150310920861259   | -4.1687371098408     | 3.0631532761509e-05  | 0.283678398915836    | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate            \n",
       "imputed_new_buses                                                -0.00846647791645789\n",
       "imputed_new_buses:single_stop_10_ride                            0.0300708654282957  \n",
       "Is405North_10_ride:I405HOV                                       0.0138578502605138  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0267878477100719 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0364850905162761  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0626606713808674 \n",
       "                                                                 Std. Error         \n",
       "imputed_new_buses                                                0.00217272646754832\n",
       "imputed_new_buses:single_stop_10_ride                            0.00644217422026693\n",
       "Is405North_10_ride:I405HOV                                       0.00493188121293141\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00440319478892845\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0123920124217862 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0150310920861259 \n",
       "                                                                 t value          \n",
       "imputed_new_buses                                                -3.89670676125714\n",
       "imputed_new_buses:single_stop_10_ride                            4.66781313266776 \n",
       "Is405North_10_ride:I405HOV                                       2.80985077746368 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -6.08372988118268\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   2.94424257129796 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.1687371098408 \n",
       "                                                                 Pr(>|t|)            \n",
       "imputed_new_buses                                                9.75153108461107e-05\n",
       "imputed_new_buses:single_stop_10_ride                            3.04458256770485e-06\n",
       "Is405North_10_ride:I405HOV                                       0.00495653461378253 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.17456732903453e-09\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00323752890842181 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 3.0631532761509e-05 \n",
       "                                                                 r2               \n",
       "imputed_new_buses                                                0.283678398915836\n",
       "imputed_new_buses:single_stop_10_ride                            0.283678398915836\n",
       "Is405North_10_ride:I405HOV                                       0.283678398915836\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.283678398915836\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.283678398915836\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.283678398915836\n",
       "                                                                 N      \n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1104348\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>r2</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                </td><td>0.0298627367907546                               </td><td>0.00599503457828382                              </td><td>4.98124512891522                                 </td><td>6.32765550056834e-07                             </td><td>0.323794699565868                                </td><td>105112                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>-0.0146371912264553                              </td><td>0.00196986842779907                              </td><td>-7.43054257832304                                </td><td>1.08230472725702e-13                             </td><td>0.283604099270915                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>0.0113941737714081                               </td><td>0.00447967203922432                              </td><td>2.54352856004634                                 </td><td>0.0109740436594509                               </td><td>0.283604099270915                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>-0.304817914528539                               </td><td>0.0402716879334351                               </td><td>-7.56903745957636                                </td><td>3.76288935610978e-14                             </td><td>0.283702478067186                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.00925924046454574                              </td><td>0.00588700606363359                              </td><td>1.57282672456273                                 </td><td>0.115759232278501                                </td><td>0.283702478067186                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>0.298464852053449                                </td><td>0.0400549575685847                               </td><td>7.45138355326925                                 </td><td>9.24331971089394e-14                             </td><td>0.283702478067186                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>0.160197831409656                                </td><td>0.0566469047270118                               </td><td>2.82800679369276                                 </td><td>0.0046839655485875                               </td><td>0.283702478067186                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.194679856895537                               </td><td>0.0566412499958205                               </td><td>-3.43706851296365                                </td><td>0.000588068486048824                             </td><td>0.283702478067186                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>-0.00727749548067217                             </td><td>0.00215394105342945                              </td><td>-3.37868832068785                                </td><td>0.000728350457894284                             </td><td>0.283667124529281                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>0.0185229731657398                               </td><td>0.0058162323422483                               </td><td>3.1847030991509                                  </td><td>0.00144906613064094                              </td><td>0.283667124529281                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0206139717882291                               </td><td>0.00465802778346495                              </td><td>4.42547205523431                                 </td><td>9.62408100455572e-06                             </td><td>0.283667124529281                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0364149490091043                              </td><td>0.003749027088264                                </td><td>-9.71317308511803                                </td><td>2.65503453034899e-22                             </td><td>0.283667124529281                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.00499202238631069                             </td><td>0.00738708166419208                              </td><td>-0.675777338500111                               </td><td>0.499182166204885                                </td><td>0.283667124529281                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>-0.00846647791645789                             </td><td>0.00217272646754832                              </td><td>-3.89670676125714                                </td><td>9.75153108461107e-05                             </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>0.0300708654282957                               </td><td>0.00644217422026693                              </td><td>4.66781313266776                                 </td><td>3.04458256770485e-06                             </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0138578502605138                               </td><td>0.00493188121293141                              </td><td>2.80985077746368                                 </td><td>0.00495653461378253                              </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0267878477100719                              </td><td>0.00440319478892845                              </td><td>-6.08372988118268                                </td><td>1.17456732903453e-09                             </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0364850905162761                               </td><td>0.0123920124217862                               </td><td>2.94424257129796                                 </td><td>0.00323752890842181                              </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0626606713808674                              </td><td>0.0150310920861259                               </td><td>-4.1687371098408                                 </td><td>3.0631532761509e-05                              </td><td>0.283678398915836                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & r2 & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                     & 0.0298627367907546                                    & 0.00599503457828382                                   & 4.98124512891522                                      & 6.32765550056834e-07                                  & 0.323794699565868                                     & 105112                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & -0.0146371912264553                               & 0.00196986842779907                               & -7.43054257832304                                 & 1.08230472725702e-13                              & 0.283604099270915                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & 0.0113941737714081                                & 0.00447967203922432                               & 2.54352856004634                                  & 0.0109740436594509                                & 0.283604099270915                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & -0.304817914528539                                & 0.0402716879334351                                & -7.56903745957636                                 & 3.76288935610978e-14                              & 0.283702478067186                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.00925924046454574                               & 0.00588700606363359                               & 1.57282672456273                                  & 0.115759232278501                                 & 0.283702478067186                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & 0.298464852053449                                 & 0.0400549575685847                                & 7.45138355326925                                  & 9.24331971089394e-14                              & 0.283702478067186                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & 0.160197831409656                                 & 0.0566469047270118                                & 2.82800679369276                                  & 0.0046839655485875                                & 0.283702478067186                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.194679856895537                                & 0.0566412499958205                                & -3.43706851296365                                 & 0.000588068486048824                              & 0.283702478067186                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & -0.00727749548067217                              & 0.00215394105342945                               & -3.37868832068785                                 & 0.000728350457894284                              & 0.283667124529281                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & 0.0185229731657398                                & 0.0058162323422483                                & 3.1847030991509                                   & 0.00144906613064094                               & 0.283667124529281                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.0206139717882291                                & 0.00465802778346495                               & 4.42547205523431                                  & 9.62408100455572e-06                              & 0.283667124529281                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0364149490091043                               & 0.003749027088264                                 & -9.71317308511803                                 & 2.65503453034899e-22                              & 0.283667124529281                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.00499202238631069                              & 0.00738708166419208                               & -0.675777338500111                                & 0.499182166204885                                 & 0.283667124529281                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & -0.00846647791645789                              & 0.00217272646754832                               & -3.89670676125714                                 & 9.75153108461107e-05                              & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & 0.0300708654282957                                & 0.00644217422026693                               & 4.66781313266776                                  & 3.04458256770485e-06                              & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & 0.0138578502605138                                & 0.00493188121293141                               & 2.80985077746368                                  & 0.00495653461378253                               & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0267878477100719                               & 0.00440319478892845                               & -6.08372988118268                                 & 1.17456732903453e-09                              & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.0364850905162761                                & 0.0123920124217862                                & 2.94424257129796                                  & 0.00323752890842181                               & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0626606713808674                               & 0.0150310920861259                                & -4.1687371098408                                  & 3.0631532761509e-05                               & 0.283678398915836                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | r2 | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                 | 0.0298627367907546                                | 0.00599503457828382                               | 4.98124512891522                                  | 6.32765550056834e-07                              | 0.323794699565868                                 | 105112                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | -0.0146371912264553                               | 0.00196986842779907                               | -7.43054257832304                                 | 1.08230472725702e-13                              | 0.283604099270915                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | 0.0113941737714081                                | 0.00447967203922432                               | 2.54352856004634                                  | 0.0109740436594509                                | 0.283604099270915                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | -0.304817914528539                                | 0.0402716879334351                                | -7.56903745957636                                 | 3.76288935610978e-14                              | 0.283702478067186                                 | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.00925924046454574                               | 0.00588700606363359                               | 1.57282672456273                                  | 0.115759232278501                                 | 0.283702478067186                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | 0.298464852053449                                 | 0.0400549575685847                                | 7.45138355326925                                  | 9.24331971089394e-14                              | 0.283702478067186                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | 0.160197831409656                                 | 0.0566469047270118                                | 2.82800679369276                                  | 0.0046839655485875                                | 0.283702478067186                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.194679856895537                                | 0.0566412499958205                                | -3.43706851296365                                 | 0.000588068486048824                              | 0.283702478067186                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | -0.00727749548067217                              | 0.00215394105342945                               | -3.37868832068785                                 | 0.000728350457894284                              | 0.283667124529281                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | 0.0185229731657398                                | 0.0058162323422483                                | 3.1847030991509                                   | 0.00144906613064094                               | 0.283667124529281                                 | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.0206139717882291                                | 0.00465802778346495                               | 4.42547205523431                                  | 9.62408100455572e-06                              | 0.283667124529281                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.0364149490091043                               | 0.003749027088264                                 | -9.71317308511803                                 | 2.65503453034899e-22                              | 0.283667124529281                                 | 1104348                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | -0.00499202238631069                              | 0.00738708166419208                               | -0.675777338500111                                | 0.499182166204885                                 | 0.283667124529281                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | -0.00846647791645789                              | 0.00217272646754832                               | -3.89670676125714                                 | 9.75153108461107e-05                              | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | 0.0300708654282957                                | 0.00644217422026693                               | 4.66781313266776                                  | 3.04458256770485e-06                              | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | 0.0138578502605138                                | 0.00493188121293141                               | 2.80985077746368                                  | 0.00495653461378253                               | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | -0.0267878477100719                               | 0.00440319478892845                               | -6.08372988118268                                 | 1.17456732903453e-09                              | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 0.0364850905162761                                | 0.0123920124217862                                | 2.94424257129796                                  | 0.00323752890842181                               | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -0.0626606713808674                               | 0.0150310920861259                                | -4.1687371098408                                  | 3.0631532761509e-05                               | 0.283678398915836                                 | 1104348                                           | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "                                                                 1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate            \n",
       "                                                                 0.0298627367907546  \n",
       "imputed_new_buses                                                -0.0146371912264553 \n",
       "imputed_new_buses:single_stop_10_ride                            0.0113941737714081  \n",
       "imputed_new_buses                                                -0.304817914528539  \n",
       "Is405North_10_ride:I405HOV                                       0.00925924046454574 \n",
       "imputed_new_buses:I405HOV                                        0.298464852053449   \n",
       "imputed_new_buses:Is405North_10_ride                             0.160197831409656   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.194679856895537  \n",
       "imputed_new_buses                                                -0.00727749548067217\n",
       "imputed_new_buses:single_stop_10_ride                            0.0185229731657398  \n",
       "Is405North_10_ride:I405HOV                                       0.0206139717882291  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0364149490091043 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.00499202238631069\n",
       "imputed_new_buses                                                -0.00846647791645789\n",
       "imputed_new_buses:single_stop_10_ride                            0.0300708654282957  \n",
       "Is405North_10_ride:I405HOV                                       0.0138578502605138  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0267878477100719 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0364850905162761  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0626606713808674 \n",
       "                                                                 Std. Error         \n",
       "                                                                 0.00599503457828382\n",
       "imputed_new_buses                                                0.00196986842779907\n",
       "imputed_new_buses:single_stop_10_ride                            0.00447967203922432\n",
       "imputed_new_buses                                                0.0402716879334351 \n",
       "Is405North_10_ride:I405HOV                                       0.00588700606363359\n",
       "imputed_new_buses:I405HOV                                        0.0400549575685847 \n",
       "imputed_new_buses:Is405North_10_ride                             0.0566469047270118 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0566412499958205 \n",
       "imputed_new_buses                                                0.00215394105342945\n",
       "imputed_new_buses:single_stop_10_ride                            0.0058162323422483 \n",
       "Is405North_10_ride:I405HOV                                       0.00465802778346495\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.003749027088264  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00738708166419208\n",
       "imputed_new_buses                                                0.00217272646754832\n",
       "imputed_new_buses:single_stop_10_ride                            0.00644217422026693\n",
       "Is405North_10_ride:I405HOV                                       0.00493188121293141\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00440319478892845\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0123920124217862 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0150310920861259 \n",
       "                                                                 t value           \n",
       "                                                                 4.98124512891522  \n",
       "imputed_new_buses                                                -7.43054257832304 \n",
       "imputed_new_buses:single_stop_10_ride                            2.54352856004634  \n",
       "imputed_new_buses                                                -7.56903745957636 \n",
       "Is405North_10_ride:I405HOV                                       1.57282672456273  \n",
       "imputed_new_buses:I405HOV                                        7.45138355326925  \n",
       "imputed_new_buses:Is405North_10_ride                             2.82800679369276  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -3.43706851296365 \n",
       "imputed_new_buses                                                -3.37868832068785 \n",
       "imputed_new_buses:single_stop_10_ride                            3.1847030991509   \n",
       "Is405North_10_ride:I405HOV                                       4.42547205523431  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -9.71317308511803 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.675777338500111\n",
       "imputed_new_buses                                                -3.89670676125714 \n",
       "imputed_new_buses:single_stop_10_ride                            4.66781313266776  \n",
       "Is405North_10_ride:I405HOV                                       2.80985077746368  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -6.08372988118268 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   2.94424257129796  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.1687371098408  \n",
       "                                                                 Pr(>|t|)            \n",
       "                                                                 6.32765550056834e-07\n",
       "imputed_new_buses                                                1.08230472725702e-13\n",
       "imputed_new_buses:single_stop_10_ride                            0.0109740436594509  \n",
       "imputed_new_buses                                                3.76288935610978e-14\n",
       "Is405North_10_ride:I405HOV                                       0.115759232278501   \n",
       "imputed_new_buses:I405HOV                                        9.24331971089394e-14\n",
       "imputed_new_buses:Is405North_10_ride                             0.0046839655485875  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.000588068486048824\n",
       "imputed_new_buses                                                0.000728350457894284\n",
       "imputed_new_buses:single_stop_10_ride                            0.00144906613064094 \n",
       "Is405North_10_ride:I405HOV                                       9.62408100455572e-06\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     2.65503453034899e-22\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.499182166204885   \n",
       "imputed_new_buses                                                9.75153108461107e-05\n",
       "imputed_new_buses:single_stop_10_ride                            3.04458256770485e-06\n",
       "Is405North_10_ride:I405HOV                                       0.00495653461378253 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.17456732903453e-09\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00323752890842181 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 3.0631532761509e-05 \n",
       "                                                                 r2               \n",
       "                                                                 0.323794699565868\n",
       "imputed_new_buses                                                0.283604099270915\n",
       "imputed_new_buses:single_stop_10_ride                            0.283604099270915\n",
       "imputed_new_buses                                                0.283702478067186\n",
       "Is405North_10_ride:I405HOV                                       0.283702478067186\n",
       "imputed_new_buses:I405HOV                                        0.283702478067186\n",
       "imputed_new_buses:Is405North_10_ride                             0.283702478067186\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.283702478067186\n",
       "imputed_new_buses                                                0.283667124529281\n",
       "imputed_new_buses:single_stop_10_ride                            0.283667124529281\n",
       "Is405North_10_ride:I405HOV                                       0.283667124529281\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.283667124529281\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.283667124529281\n",
       "imputed_new_buses                                                0.283678398915836\n",
       "imputed_new_buses:single_stop_10_ride                            0.283678398915836\n",
       "Is405North_10_ride:I405HOV                                       0.283678398915836\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.283678398915836\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.283678398915836\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.283678398915836\n",
       "                                                                 N      \n",
       "                                                                 105112 \n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "imputed_new_buses                                                1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:I405HOV                                        1104348\n",
       "imputed_new_buses:Is405North_10_ride                             1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1104348\n",
       "                                                                 granularity                                      \n",
       "                                                                 rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>used</th><th scope=col>(Mb)</th><th scope=col>gc trigger</th><th scope=col>(Mb)</th><th scope=col>max used</th><th scope=col>(Mb)</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>Ncells</th><td>  666234  </td><td> 35.6     </td><td>  2373532 </td><td> 126.8    </td><td>  11317888</td><td>  604.5   </td></tr>\n",
       "\t<tr><th scope=row>Vcells</th><td>74863600  </td><td>571.2     </td><td>998675794 </td><td>7619.3    </td><td>1762545297</td><td>13447.2   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllll}\n",
       "  & used & (Mb) & gc trigger & (Mb) & max used & (Mb)\\\\\n",
       "\\hline\n",
       "\tNcells &   666234   &  35.6      &   2373532  &  126.8     &   11317888 &   604.5   \\\\\n",
       "\tVcells & 74863600   & 571.2      & 998675794  & 7619.3     & 1762545297 & 13447.2   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | used | (Mb) | gc trigger | (Mb) | max used | (Mb) |\n",
       "|---|---|---|---|---|---|---|\n",
       "| Ncells |   666234   |  35.6      |   2373532  |  126.8     |   11317888 |   604.5    |\n",
       "| Vcells | 74863600   | 571.2      | 998675794  | 7619.3     | 1762545297 | 13447.2    |\n",
       "\n"
      ],
      "text/plain": [
       "       used     (Mb)  gc trigger (Mb)   max used   (Mb)   \n",
       "Ncells   666234  35.6   2373532   126.8   11317888   604.5\n",
       "Vcells 74863600 571.2 998675794  7619.3 1762545297 13447.2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "gc()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
